<!--
 * @Description:只能输入数字的输入框
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-07 22:21:27
 -->
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>只能输入数字的输入框</title>
	<style>
		* {
			margin: 0;
			padding: 0;
			list-style: none;
		}

		#div1 {
			width: 80px;
			/* height: 100px; */
			border: 1px solid black;
			background: #ccc;
			display: none;
			position: absolute;
		}
	</style>

</head>
<script>
	window.onload = function () {

		var otxt = document.getElementById('input1')
		otxt.onkeydown=function(ev){
			var oEvent = ev || event
			console.log(ev.keyCode)
			//0-9 48-57
			//
			if(oEvent.keyCode!=8&&oEvent.keyCode<48|| oEvent.keyCode>57){
				return false
			}
				console.log("scv"+ev.keyCode)
		}
	

	}
</script>

<body>
	oncontextmenu 菜单事件<br>
  <input type="text" id="input1">

</body>

</html>